Socket
Socket
Sign inDemoInstall

@salesforce/ts-sinon

Package Overview
Dependencies
Maintainers
0
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@salesforce/ts-sinon

TypeScript helpers for Sinon


Version published
Weekly downloads
34K
increased by4.26%
Maintainers
0
Weekly downloads
 
Created
Source

TypeScript-friendly utils for Sinon testing

This is a simple library to help create stubs with Sinon when working with TypeScript in order to leverage Sinon stubs and the type system more completely together as one without resorting to ugly, untyped hacks like casting stubbed functions to any or using associative array accesses, neither of which provide IDE-autocompletion of stub properties and methods, nor work well with stricter tsc and tslint rules applied to test sources.

API

The API consists of the following functions:

stubInterface

Used to provide a fully stubbed interface backed by an optional set of member properties which may form a subset of the overall interface. Function properties will be typed as proper SinonStubs along with any other specific type information provided by the interface.

stubObject

Returns a fully stubbed proxy similar to those provided by stubInterface, but backed first by the optionally given members, and finally by a given object. This is useful for stubbing some properties of an existing object while providing test-specific returns for fakes for others.

stubCallable

Like stubObject but works with callable TypeScript function types (i.e., functions with properties).

fromStub

When using stubObject with objects created from classes with non-public members, the resulting StubbedType<T> often needs to be passed to a function or constructor that expects a T, but TypeScript's mapped types (which are the basis of StubbedType) do not capture non-public class members. Since the StubbedType returned from stubObject is backed by a real instance of type T, it can be simply reverted to type T by using fromStub(instance). The implementation of this simply applies a type assertion, but using fromStub is preferred for clarity, especially given that this library exists to reduce the necessity of using type assertions in tests in the first place.

FAQs

Package last updated on 12 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc